package com.bank.basic.controller;

import com.bank.basic.service.DepositService;
import com.bank.basic.service.impl.DepositServiceImpl;
import com.bank.common.commonUtil.AuthContextHolderUtil;
import com.bank.model.entity.Deposit;
import com.bank.model.vo.deposit.CashDepositVo;
import com.bank.model.vo.deposit.DepositAddVo;
import com.bank.model.vo.deposit.DepositHistoryVo;
import com.bank.model.vo.deposit.DepositVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author Cejay1314
 * @version 1.0
 * @create 2023/2/5 22:52
 */


@RestController
@RequestMapping(value = "/basic/deposit")
public class DepositController {
    @Autowired
    DepositService depositService;

    @GetMapping
    public String hello(){
        return "hello";
    }
    @GetMapping("/basic")
    public String basic(){
        return "hello";
    }

    @PostMapping("/cash")
    public void cashDeposit(@RequestBody CashDepositVo cashDepositVo){
        depositService.cashDeposit(cashDepositVo);
    }
    @GetMapping("/list")
    public List<DepositVo> cashDeposit(HttpServletRequest httpServletRequest){
        long userId = AuthContextHolderUtil.getUserId(httpServletRequest);
        return depositService.queryList(userId);
    }
    @GetMapping("/history")
    public List<DepositHistoryVo> queryDepositHistoryVos(){
        return depositService.queryDepositHistoryVos();
    }
    @GetMapping("/all")
    public List<Deposit> queryAll(){
        return depositService.queryAll();
    }
    @GetMapping("/account")
    public List<Deposit> queryAccount(@RequestParam String accountId){
        return depositService.queryAccount(accountId);
    }
    @GetMapping("/user")
    public List<Deposit> queryUser(@RequestParam Long userId){
        return depositService.queryUser(userId);
    }
    @GetMapping("/account/money")
    public Double getAccountMoney(@RequestParam String accountId){
        return depositService.getAccountMoney(accountId);
    }
    @GetMapping("/user/money")
    public Double getUserMoney(@RequestParam Long userId){
        return depositService.getUserMoney(userId);
    }
    @PostMapping("/add")
    void addDeposit(@RequestBody DepositAddVo depositAddVo, HttpServletRequest httpServletRequest){
        depositService.addDeposit(depositAddVo,httpServletRequest);
    }
    @GetMapping("/del")
    void delDeposit(@RequestParam Long depositId){
        depositService.delDeposit(depositId);
    }

}
